package com.abe.quick;

import android.content.Intent;
import android.os.Bundle;

import com.abe.libcore.base.permission.PermissionUtils;
import com.abe.libquick.base.BaseActivity;
import com.abe.libquick.main.audio.AudioMainActivity;
import com.abe.libquick.main.video.player.VideoPlayerActivity;
import com.abe.libquick.main.video.player.VideoRecordHelper;
import com.abe.libquick.widget.form.FormSpinnerView;
import com.yanzhenjie.permission.runtime.Permission;

import java.util.Arrays;

public class MainActivity extends BaseActivity {
    FormSpinnerView spinnerView;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_main;
    }

    @Override
    protected void initContent() {
        spinnerView = findViewById(R.id.item_name);
        test();
    }

    private void test() {
        String[] x = {"短视频", "录音"};
        spinnerView.setData(Arrays.asList(x));
        spinnerView.setListener((parent, view, position, id) -> {
            switch (position) {
                case 0:
                    gotoVideoRecord();
                    break;
                case 1:
                    gotoAudioRecord();
                    break;
            }
        });
    }

    private void gotoAudioRecord() {
        PermissionUtils.INSTANCE.request(this, () ->
                gotoActivity(AudioMainActivity.class), Permission.RECORD_AUDIO);
    }

    private void gotoVideoRecord() {
        VideoRecordHelper.recordAndPreview(MainActivity.this, 0x001, 16000);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK || data == null) return;
        if (requestCode == 0x001) {
            Bundle bundle = data.getExtras();
            gotoActivity(VideoPlayerActivity.class, bundle);
        }
    }
}